package com.ruoyi.eservice.service.impl;

import java.util.List;
import java.util.Arrays;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.base.BaseService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.eservice.mapper.DishFlavorMapper;
import com.ruoyi.eservice.pojo.entity.DishFlavor;
import com.ruoyi.eservice.service.IDishFlavorService;

/**
 * 菜品口味关系Service业务层处理
 *
 * @author Jackson
 * @date 2022-11-11
 */
@Service
public class DishFlavorServiceImpl extends BaseService implements IDishFlavorService
{
    @Autowired
    private DishFlavorMapper dishFlavorMapper;

    /**
     * 查询菜品口味关系
     *
     * @param dishFlavorId 菜品口味关系主键
     * @return 菜品口味关系
     */
    @Override
    public DishFlavor selectDishFlavorByDishFlavorId(Long dishFlavorId)
    {
        return dishFlavorMapper.selectById(dishFlavorId);
    }

    /**
     * 查询菜品口味关系列表
     *
     * @param dishFlavor 菜品口味关系
     * @return 菜品口味关系
     */
    @Override
    public List<DishFlavor> selectDishFlavorList(DishFlavor dishFlavor)
    {
        QueryWrapper<DishFlavor> queryWrapper = createSelWrapper(DishFlavor.class);
        queryWrapper.lambda()
                .eq(StringUtils.isNotNull(dishFlavor.getDishFlavorId()), DishFlavor::getDishFlavorId, dishFlavor.getDishFlavorId())
                .eq(StringUtils.isNotNull(dishFlavor.getDishId()), DishFlavor::getDishId, dishFlavor.getDishId())
                .like(StringUtils.isNotEmpty(dishFlavor.getName()), DishFlavor::getName, dishFlavor.getName())
                .eq(StringUtils.isNotEmpty(dishFlavor.getValue()), DishFlavor::getValue, dishFlavor.getValue())
                .eq(StringUtils.isNotNull(dishFlavor.getIsDeleted()), DishFlavor::getIsDeleted, dishFlavor.getIsDeleted())
                .eq(StringUtils.isNotEmpty(dishFlavor.getStatus()), DishFlavor::getStatus, dishFlavor.getStatus())
        ;
        return dishFlavorMapper.selectList(queryWrapper);
    }

    /**
     * 新增菜品口味关系
     *
     * @param dishFlavor 菜品口味关系
     * @return 结果
     */
    @Override
    public int insertDishFlavor(DishFlavor dishFlavor)
    {
        dishFlavor.setCreateBy(SecurityUtils.getUsername());
        dishFlavor.setCreateTime(DateUtils.getNowDate());
        dishFlavor.setUpdateBy(SecurityUtils.getUsername());
        dishFlavor.setUpdateTime(DateUtils.getNowDate());
        int rows = dishFlavorMapper.insert(dishFlavor);
        return rows;
    }

    /**
     * 修改菜品口味关系
     *
     * @param dishFlavor 菜品口味关系
     * @return 结果
     */
    @Override
    public int updateDishFlavor(DishFlavor dishFlavor)
    {
        dishFlavor.setUpdateBy(SecurityUtils.getUsername());
        dishFlavor.setUpdateTime(DateUtils.getNowDate());

        return dishFlavorMapper.updateById(dishFlavor);
    }

    /**
     * 批量删除菜品口味关系
     *
     * @param dishFlavorIds 需要删除的菜品口味关系主键
     * @return 结果
     */
    @Override
    public int deleteDishFlavorByDishFlavorIds(Long[] dishFlavorIds)
    {
        return dishFlavorMapper.deleteBatchIds(Arrays.asList(dishFlavorIds));
    }

    /**
     * 删除菜品口味关系信息
     *
     * @param dishFlavorId 菜品口味关系主键
     * @return 结果
     */
    @Override
    public int deleteDishFlavorByDishFlavorId(Long dishFlavorId)
    {
        return dishFlavorMapper.deleteById(dishFlavorId);
    }
}
